package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.WmNewsDto;
import com.heima.model.wemedia.dto.WmNewsPageReqDto;
import com.heima.model.wemedia.entity.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(path = "/api/v1/news")
public class WmNewsController {

    @Resource
    private WmNewsService wmNewsService;

    /**
     * 自媒体文章发布 --- 保存草稿 --- 修改
     * @param dto
     * @return
     */
    @PostMapping(path = "/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto){

        return wmNewsService.submit(dto);
    }

    /**
     * 条件查询自媒体文章列表
     * @param dto
     * @return
     */
    @PostMapping(path = "list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto dto){
        return wmNewsService.list(dto);
    }

    /**
     *
     * @return根据文章id查询文章详情
     */
    @GetMapping(path = "/one/{id}")
    public ResponseResult findOne(@PathVariable("id") Long id){

        WmNews wmNews = wmNewsService.queryById(id);
        return ResponseResult.okResult(wmNews);

    }

    /**
     * 根据id删除文章
     * @return
     */
    @GetMapping(path = "/del_news/{id}")
    public ResponseResult delete(@PathVariable("id") Long id){
        return wmNewsService.deleteById(id);
    }
}
